home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7102 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  62 lines

  1. Path: news1.cris.com!news
  2. From: aubrey@concentric.net (Aubrey Harrison)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C beginner needs your help ASAP
  5. Date: 18 Feb 1996 22:51:25 GMT
  6. Organization: Concentric Internet Services
  7. Distribution: world
  8. Message-ID: <4g8ahd$p8b@spectator.cris.com>
  9. References: <4g862f$p0b@risky.ecs.umass.edu>
  10. NNTP-Posting-Host: cnc022033.concentric.net
  11. Mime-Version: 1.0
  12. Content-Type: Text/Plain; charset=US-ASCII
  13. X-Newsreader: WinVN 0.99.6
  14.  
  15. In article <4g862f$p0b@risky.ecs.umass.edu>, sebag@ecs.umass.edu says...
  16. >
  17. >I am a new C programmmer who desperately needs help.
  18. >I have been digging in the manuals for a way to do this but have still
  19. >come out empty handed. Here is the problem: I want to open files in a while
  20. >loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
  21. >I need to increment an integer each time around then convert it to a string
  22. >and then somehow use strcat to combine the "data" with the integer string.
  23. >After that use fopen(filename, "a");
  24. >
  25. >If you know how to do this, please email me. It would take you 2 minutes but
  26. >it is taking me two days so far. Code would be extremly useful.
  27. >Thanks, sebag@ecs.umass.edu
  28.  
  29. This is how I would do it. I tested it and it seems to do what you want. Of 
  30. course, I am no expert, in fact I was called "ignorant and idiot" by Mister Dan 
  31. Pop, the self-appointed comp.lang.c.police, for helping someone earlier, so I 
  32. guess I am not worthy of posting here, but somehow I feel a little better after 
  33. helping someone, instead of attacking and belittling them because I somehow see 
  34. myself as superior when I don't really know anything about them.
  35.  
  36. #include <stdio.h>
  37.  
  38. main()
  39. {
  40.         char buf[3],filename[9];
  41.         int  i;
  42.  
  43.         for(i=0; i<10; i++)
  44.         {
  45.                 sprintf(buf,"%d",i);
  46.                 strcpy( filename,"data");
  47.                 strcat( filename, buf );
  48.                 strcat( filename, ".ext");
  49.                 printf( "%s\n", filename);
  50.         }
  51.  
  52. }
  53.  
  54. -- 
  55. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  56. Aubrey Harrison    aubrey@concentric.net    75320.1606@compuserve.com
  57. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  58. Loneliness is to endure the presence of one who does not understand.
  59.                                          -Elbert Hubbard (1856-1915)
  60. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  61.  
  62.